package com.example.scanfast.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SingletonThreadPool {

    private static SingletonThreadPool instance = null;
    private final ExecutorService threadPool;

    private SingletonThreadPool() {
        // 使用Executors创建一个固定大小为1的线程池，你可以根据需求选择不同的线程池类型和大小
        threadPool = Executors.newFixedThreadPool(1);
    }

    public static synchronized SingletonThreadPool getInstance() {
        if (instance == null) {
            instance = new SingletonThreadPool();
        }
        return instance;
    }

    public void executeTask(Runnable task) {
        threadPool.execute(task);
    }

    public void shutdown() {
        threadPool.shutdown();
    }
}
